<?php
declare(strict_types=1);
namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Service\GoodsService\GoodsCommentService;

/**
 * 评论接口
 * @author Luoshumai
 * @Controller(prefix="/webapi/v1/comment")
 */
class CommentController extends AbstractController
{
    /**
     * @Inject()
     * @var GoodsCommentService
     */
    protected $goodsCommentService;

    /**
     * 评论列表接口
     * @RequestMapping(path="index", methods="post")
     */
    public function index(RequestInterface $request)
    {
        return $this->goodsCommentService->getComments(
            (int)$request->input('goods_id'),
            (int)$request->input('page',1),
            (int)$request->input('limit',10),
            (int)$request->input('tag_id'),
            (int)$request->input('cid'),
            28327
        );

    }

    /**
     * 评论标签接口
     * @RequestMapping(path="tag", methods="post")
     */
    public function tag(RequestInterface $request)
    {
        return $this->goodsCommentService->getTags(
            (int)$request->input('cid')
        );
    }

    /**
     * 发表评论接口
     * @RequestMapping(path="addComment", methods="post")
     */
    public function addComment(RequestInterface $request)
    {
        return $this->goodsCommentService->addComment(
            (array)$request->input('comment_list'),
            (int)$request->input('cid'),
            (string)$request->input('sn'),
            (int)$request->input('anonymity'),
            28327
        );
    }

    /**
     * 评论点赞
     * @RequestMapping(path="doLikeComment", methods="post")
     */
    public function doLikeComment(RequestInterface $request)
    {
        return $this->goodsCommentService->doLikeComment(
            (int)$request->input('cid'),
            (int)$request->input('comment_id'),
            28327
        );
    }

    /**
     * 评论点赞
     * @RequestMapping(path="cancelLikeComment", methods="post")
     */
    public function cancelLikeComment(RequestInterface $request)
    {
        return $this->goodsCommentService->cancelLikeComment(
            (int)$request->input('cid'),
            (int)$request->input('comment_id'),
            28327
        );
    }


}